<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      let count = 0;

      let ws = new WebSocket("ws://localhost:3000/ws/chat");

      ws.onopen = function () {
        console.log(`[CLIENT] open()`);
        ws.send("Hello!");
      };

      ws.onmessage = function (message) {
        console.log(`[CLIENT] Received: ${message}`);
        count++;
        // if (count > 3) {
        //   ws.send("Goodbye!");
        //   ws.close();
        // } else {
        //   setTimeout(() => {
        //     ws.send(`Hello, I'm Mr No.${count}!`);
        //   }, 1000);
        // }
      };
    </script>
  </body>
</html>
